package ink.teamwork.order.service.impl;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import ink.teamwork.order.dao.OrderDAO;
import ink.teamwork.order.entity.Order;
import ink.teamwork.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
@Transactional
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDAO orderDAO;

    @Override
    public boolean save(Order order) {
        return orderDAO.save(order);
    }

    @Override
    public boolean update(Order order) {
        try {
            orderDAO.save(order);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    @Override
    public SearchResult<Order> queryPageByUserId(int strat, int size, String userId) {
        Search search = new Search();
        search.addFilterEqual("userId", userId);
        search.setFirstResult(strat);
        search.setMaxResults(size);
        return orderDAO.searchAndCount(search);
    }
}
